﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel;
using System.Collections.Generic;
namespace WPFExcelReport
{
    public partial class UIMAXORD : ViewBase
    {

        public DataTable TBResult;
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return; 
            LOADALL();
            base.Window_Loaded(sender, e);
        }
        public override void LOADALL()
        {
            try
            { 
                TMV.sql = "SELECT* FROM ICC_MAXORD";
                TBResult = TMV.SQLiteDatabase.GetDataTable(TMV.sql);
                TBResult.TableName = TMV.TableName; 
                foreach(DataRow row in TBResult.Rows)
                {
                    MAXORD = int.Parse(row["MAXORD"].ToString());
                    USD2RMB =double.Parse( row["USD2RMB"].ToString());
                    RATE1 = double.Parse(row["RATE1"].ToString());
                }
               
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex.Message);
            }
            base.LOADALL();
        }
        public override void OnEXAUFChg(string vlaue)
        { 
           
            base.OnEXAUFChg(vlaue);
        }
        public void GETORD()
        {
            TMV.GETORD();
            LOADALL();
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if (dwMaster == null)
            {
                KEY = ""; 
            }
            else
            {
                KEY = TMV.MAXORD.ToString();
                USD2RMB = TMV.USD2RMB;
                RATE1 = TMV.RATE1;
            }
        }
    }
    public partial class UIMAXORD
    {
        public VICC_MAXORD TMV
        {
            get
            {
                return (VICC_MAXORD)MV;
            }
        }
        #region ==MAXORD===========
        public static readonly DependencyProperty MAXORDProperty = DependencyProperty.Register("MAXORD",
            typeof(int), typeof(UIMAXORD),
            new FrameworkPropertyMetadata(1, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMAXORDChanged));
        public int MAXORD
        {
            get
            {
                return (int)GetValue(MAXORDProperty);
            }
            set
            {
                SetValue(MAXORDProperty, value);
                OnMAXORDChg();
            }
        }
        private static void OnMAXORDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMAXORD;
            if (src != null)
            {
                src.MAXORD = (int)e.NewValue;
            }
        }
        public virtual void OnMAXORDChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.MAXORD = MAXORD;
        }
        #endregion
        #region ==USD2RMB===========
        public static readonly DependencyProperty USD2RMBProperty = DependencyProperty.Register("USD2RMB",
            typeof(double), typeof(UIMAXORD),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnUSD2RMBChanged));
        public double USD2RMB
        {
            get
            {
                return (double)GetValue(USD2RMBProperty);
            }
            set
            {
                SetValue(USD2RMBProperty, value);
                OnUSD2RMBChg();
            }
        }
        private static void OnUSD2RMBChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMAXORD;
            if (src != null)
            {
                src.USD2RMB = (double)e.NewValue;
            }
        }
        public virtual void OnUSD2RMBChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.USD2RMB = USD2RMB;
        }
        #endregion
        #region ==RATE1===========
        public static readonly DependencyProperty RATE1Property = DependencyProperty.Register("RATE1",
            typeof(double), typeof(UIMAXORD),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnRATE1Changed));
        public double RATE1
        {
            get
            {
                return (double)GetValue(RATE1Property);
            }
            set
            {
                SetValue(RATE1Property, value);
                OnRATE1Chg();
            }
        }
        private static void OnRATE1Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMAXORD;
            if (src != null)
            {
                src.RATE1 = (double)e.NewValue;
            }
        }
        public virtual void OnRATE1Chg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.RATE1 = RATE1;
        }
        #endregion

    }
}
